<template>
  <chart :option="option" :height="`${height}px`" />
  <chart :option="option2" :height="`${height}px`" />
  <chart :option="option3" :height="`${height}px`" />
</template>

<script setup>
import chart from "@/components/chart/index";
import { echartsApi } from "@/api/statistics";
import {gradientColors, option, option2, option3} from "./chartData.js"
defineProps(["height"])

//  近五年度纵向，横向，校级项目量统计
const fiveYProjectsStats = async () => {
  const res = await echartsApi.fiveYProjectsStats()
  if (res.code == 200) {
    let seriesData = []
    let xAxisData = []    
    res.data.forEach((item, index) => {
      seriesData.push({
        value: item.projectNum,
        itemStyle: {
          color: index%2===0 ? gradientColors[0] : gradientColors[1]
        }
      })
      xAxisData.push(item.annual)
    });
    option.value.xAxis.data = xAxisData
    option.value.series[0].data = seriesData
  }
};

// 本年度学院科研立项经费TOP5 [项目总经费,到账经费]
const researchFundingTop5 = async () => {
  const res = await echartsApi.researchFundingTop5()
  if (res.code == 200) {
    let xAxisData = []
    let seriesData = []
    let seriesData2 = []
    
    res.data.forEach((item, index) => {
      xAxisData.push(item.unitName)
      seriesData.push(item.income/10000)
      seriesData2.push(item.authorize/10000)
    })
    option2.value.xAxis.data = xAxisData
    option2.value.series[0].data = seriesData
    option2.value.series[1].data = seriesData2
  }
};

// 近五年论文发表  
const fiveYPaperStats = async () => {
  const res = await echartsApi.fiveYPaperStats()
  if (res.code == 200) {
    let xAxisData = []
    let seriesData = []
    
    res.data.forEach((item, index) => {
      xAxisData.push(item.annual)
      seriesData.push(item.paperNum)
    })
    option3.value.xAxis.data = xAxisData
    option3.value.series[0].data = seriesData
  }
};

fiveYProjectsStats()
researchFundingTop5()
fiveYPaperStats()
</script>